import pymysql

conn = pymysql.connect(host="rm-bp17qb8fy4bpt607xio.mysql.rds.aliyuncs.com", port=33016, user="gs_product", password="$$Gs1106", database="gs_data", charset="utf8mb4")


def queryParams():
    try:
        with conn.cursor() as cursor:
            cursor.execute('select * from gs_data.gs_product_month_aim a  where  a.ep_id=1 and  a.year_mon = "2025-01"')
            row = cursor.fetchone()
            while row:
                print(row)
                row = cursor.fetchone()
    except Exception as e:
        print(e)
    finally:
        conn.close()


def insertData():
    id = int(input("主键："))
    name= input("姓名：")

    try:
        with conn.cursor() as cursor:
            affect_rows = cursor.execute('insert into `t_employee` values (%s, %s)', (id, name))
            if affect_rows == 1:
                print("新增成功")
        conn.commit()
    except Exception as e:
        print(e)
    finally:
        conn.close()

def deleteData():
    id = int(input("id="))
    try:
        with conn.cursor() as cursor:
            affect_rows = cursor.execute('delete from `t_employee` where id=%s', (id))
            if affect_rows == 1:
                print("删除成功")
        conn.commit()
    except Exception as e:
        print(e)
    finally:
        conn.close()

def updateData():
    id = int(input("id="))
    name = input("name=")
    try:
        with conn.cursor() as cursor:
            effect_row = cursor.execute('update `t_employee` set name=%s where id=%s', (name, id))
            if effect_row == 1:
                print("更新成功")
        conn.commit()
    except Exception as e:
        print(e)
    finally:
        conn.close()


if __name__ == '__main__':
    #insertData()
    updateData()
    #deleteData()
    #queryParams()
